﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Parser
{
    /// <summary>
    /// Represents a Visitor
    /// </summary>
    /// 
    /// <author>Alexander Seeliger </author>
    public class Visitor
    {
        /// <summary>
        /// Website identification number
        /// </summary>
        private int siteId;

        /// <summary>
        /// Returns or sets the identification number of the website
        /// </summary>
        public int SiteId
        {
            get { return siteId; }
            set { siteId = value; }
        }

        /// <summary>
        /// Visitor ip address
        /// </summary>
        private string visitorIp;

        /// <summary>
        /// Returns or sets the visitor ip address
        /// </summary>
        public string VisitorIp
        {
            get { return visitorIp; }
            set { visitorIp = value; }
        }

        /// <summary>
        /// Time the visitor has first access the website
        /// </summary>
        private DateTime visitorFirstAction;

        /// <summary>
        /// Returns or sets the first access time
        /// </summary>
        public DateTime VisitorFirstAction
        {
            get { return visitorFirstAction; }
            set { visitorFirstAction = value; }
        }

        /// <summary>
        /// Time the visitor has left the website
        /// </summary>
        private DateTime visitorLastAction;

        /// <summary>
        /// Returns or sets the last visited access time
        /// </summary>
        public DateTime VisitorLastAction
        {
            get { return visitorLastAction; }
            set { visitorLastAction = value; }
        }

        /// <summary>
        /// Total actions of this visitor
        /// </summary>
        private int visitorTotalAction;

        /// <summary>
        /// Returns or sets the total actions of the visitor
        /// </summary>
        public int VisitorTotalAction
        {
            get { return visitorTotalAction; }
            set { visitorTotalAction = value; }
        }

        /// <summary>
        /// Operation system the visitor has installed
        /// </summary>
        private string os;

        /// <summary>
        /// Returns or sets the operation system the user has been installed
        /// </summary>
        public string OS
        {
            get { return os; }
            set { os = value; }
        }

        /// <summary>
        /// Webbrower the user visits the site
        /// </summary>
        private string webbrowser;

        /// <summary>
        /// Returns or sets the webbrowser the user has visited the site
        /// </summary>
        public string WebBrowser
        {
            get { return webbrowser; }
            set { webbrowser = value; }
        }

        /// <summary>
        /// Webbrowser version
        /// </summary>
        private string webbrowserVersion;

        /// <summary>
        /// Returns or sets the webbrowser version
        /// </summary>
        public string WebBrowserVersion
        {
            get { return webbrowserVersion; }
            set { webbrowserVersion = value; }
        }

        /// <summary>
        /// Entry site (first site the user visits)
        /// </summary>
        private string entrySite;

        /// <summary>
        /// Returns or sets the entry site
        /// </summary>
        public string EntrySite
        {
            get { return entrySite; }
            set { entrySite = value; }
        }

        /// <summary>
        /// Referer
        /// </summary>
        private string referer;

        /// <summary>
        /// Returns or sets the referer
        /// </summary>
        public string Referer
        {
            get { return referer; }
            set { referer = value; }
        }

        /// <summary>
        /// Number of site visits
        /// </summary>
        private int siteVisits;

        /// <summary>
        /// Returns or sets the site visits
        /// </summary>
        public int SiteVisits
        {
            get { return siteVisits; }
            set { siteVisits = value; }
        }

        /// <summary>
        /// Visitor type
        /// </summary>
        private VisitorTypeEnum visitorType;

        /// <summary>
        /// Returns or sets the visitor type
        /// </summary>
        public VisitorTypeEnum VisitorType
        {
            get { return visitorType; }
            set { visitorType = value; }
        }

        /// <summary>
        /// Traffic that has been sent to this user
        /// </summary>
        private long trafficSent;

        /// <summary>
        /// Returns or sets the traffic the user has been sent to
        /// </summary>
        public long TrafficSent
        {
            get { return trafficSent; }
            set { trafficSent = value; }
        }

        /// <summary>
        /// Traffic that has been sent by the user
        /// </summary>
        private long trafficGet;

        /// <summary>
        /// Returns or sets the traffic the user has been sent to the server
        /// </summary>
        public long TrafficGet
        {
            get { return trafficGet; }
            set { trafficGet = value; }
        }

        /// <summary>
        /// Type of visitor
        /// </summary>
        public enum VisitorTypeEnum
        {
            User = 0,
            Searchbot = 1
        }

        /// <summary>
        /// Returns the type of visitor
        /// </summary>
        /// <param name="useragent">The user agent string</param>
        /// <returns>Returns a VisitorTypeEnum</returns>
        public static VisitorTypeEnum getVisitorType(string useragent)
        {
            if (useragent.ToLower().Contains("msnbot") ||
                useragent.ToLower().Contains("slurp") ||
                useragent.ToLower().Contains("mj12bot") ||
                useragent.ToLower().Contains("google"))
            {
                return VisitorTypeEnum.Searchbot;
            }
            else
            {
                return VisitorTypeEnum.User;
            }
        }
    }
}
